home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / AMDoc_0_9.lha / AMDoc / simple.m < prev    next >
Text File  |  1994-08-07  |  9KB  |  364 lines

  1. /*
  2.  * Amiga MUD
  3.  *
  4.  * Copyright (c) 1994 by Chris Gray
  5.  */
  6.  
  7. /*
  8.  * simple.m - a very simple text-only adventure. Mostly just a tutorial.
  9.  */
  10.  
  11.  
  12. /* First, define the basic "properties" that we will use in this world */
  13.  
  14. /* Properties on rooms: */
  15.  
  16. public north CreateThingProp().       /* the room to the north (if any) */
  17. public south CreateThingProp().       /* the room to the south (if any) */
  18. public east CreateThingProp().          /* the room to the east (if any) */
  19. public west CreateThingProp().          /* the room to the west (if any) */
  20. public desc CreateStringProp().       /* the description of the room */
  21. public contents CreateThingListProp()./* the list of stuff in the room */
  22.  
  23. /* Properties on players: */
  24.  
  25. public carrying CreateThingListProp()./* the list of stuff being carried */
  26.  
  27. /* Properties on objects: */
  28.  
  29. public name CreateStringProp().       /* internal-form name of object */
  30.  
  31.  
  32. /* use this short name to avoid some typing */
  33.  
  34. public G CreateGrammar().
  35.  
  36.  
  37. /* The rooms in our world: */
  38. /* First, create them all so we can reference them */
  39.  
  40. public clearing CreateThing(nil).
  41. public forestNorth CreateThing(nil).
  42. public forestSouth CreateThing(nil).
  43. public dam CreateThing(nil).
  44. public forestEast CreateThing(nil).
  45. public forestWest CreateThing(nil).
  46. public overlook CreateThing(nil).
  47. public forestNorthWest CreateThing(nil).
  48. public outsideHut CreateThing(nil).
  49. public insideHut CreateThing(nil).
  50.  
  51. /* Now put in their descriptions and interconnections. Also give each one a
  52.    'contents', so objects can be there. */
  53.  
  54. clearing@contents := CreateThingList().
  55. clearing@desc :=
  56.     "You are standing in a small clearing in a forest. You can go in several "
  57.     "directions from here.\n".
  58. clearing@north := forestNorth.
  59. clearing@south := forestSouth.
  60. clearing@east := forestEast.
  61. clearing@west := forestWest.
  62.  
  63. forestNorth@contents := CreateThingList().
  64. forestNorth@desc :=
  65.     "You are in the forest. The clearing is to your south. You can also go "
  66.     "to the west, but other directions are blocked by the undergrowth.\n".
  67. forestNorth@south := clearing.
  68. forestNorth@west := forestNorthWest.
  69.  
  70. forestSouth@contents := CreateThingList().
  71. forestSouth@desc :=
  72.     "You are in the forest, south of the clearing. There is a small path "
  73.     "here, leading west by a small stream.\n".
  74. forestSouth@north := clearing.
  75. forestSouth@west := dam.
  76.  
  77. dam@contents := CreateThingList().
  78. dam@desc :=
  79.     "You have come to a dam on the stream. The rocky gully here prevents you "
  80.     "from going anywhere but back to the east.\n".
  81. dam@east := forestSouth.
  82.  
  83. forestEast@contents := CreateThingList().
  84. forestEast@desc :=
  85.     "You are in the forest. Thick bushes and trees prevent you from going "
  86.     "anywhere except back west.\n".
  87. forestEast@west := clearing.
  88.  
  89. forestWest@contents := CreateThingList().
  90. forestWest@desc :=
  91.     "You are in the forest. A rocky ridge to the west prevents you from going "
  92.     "further in that direction, but you can wander through the trees in the "
  93.     "other directions.\n".
  94. forestWest@east := clearing.
  95. forestWest@north := forestNorthWest.
  96. forestWest@south := overlook.
  97.  
  98. overlook@contents := CreateThingList().
  99. overlook@desc :=
  100.     "You have come to the edge of a small cliff. You can see down into a "
  101.     "rocky gully here, where there is a dam across a small stream.\n".
  102. overlook@north := forestWest.
  103.  
  104. forestNorthWest@contents := CreateThingList().
  105. forestNorthWest@desc :=
  106.     "You are in the forest. You can't see much here, but you can go in "
  107.     "several directions through the thick bushes.\n".
  108. forestNorthWest@east := forestNorth.
  109. forestNorthWest@north := outsideHut.
  110. forestNorthWest@south := forestWest.
  111.  
  112. outsideHut@contents := CreateThingList().
  113. outsideHut@desc :=
  114.     "You are standing outside a log hut in the forest. You can go north into "
  115.     "the hut, or back south into the forest.\n".
  116. outsideHut@south := forestNorthWest.
  117. outsideHut@north := insideHut.
  118.  
  119. insideHut@contents := CreateThingList().
  120. insideHut@desc :=
  121.     "You are inside a small hut. It looks like a trapper or hunter uses this "
  122.     "hut during the winter, but there is no-one here now. The door out is "
  123.     "to the south.\n\nSitting on the floor here is a large chest, securely "
  124.     "locked with an iron padlock.\n".
  125. insideHut@south := outsideHut.
  126.  
  127.  
  128. /* Create the objects in the world: */
  129.  
  130. public ironKey CreateThing(nil).
  131. ironKey@name := "key;iron".
  132. AddTail(dam@contents, ironKey).     /* put it at the dam */
  133.  
  134. public rock CreateThing(nil).
  135. rock@name := "rock;small".
  136. AddTail(overlook@contents, rock).    /* put it at the overlook */
  137.  
  138.  
  139. /* Now create the commands in the world. */
  140.  
  141. /* First, some handy utilities. */
  142.  
  143. public proc showAgent(thing who)void:
  144.  
  145.     Print(who@p_pName + " is here.\n");
  146. corp;
  147.  
  148. public proc lookAround()void:
  149.     int n, i;
  150.  
  151.     Print(Here()@desc);
  152.     n := Count(Here()@contents);
  153.     if n ~= 0 then
  154.     Print("Nearby:\n");
  155.     for i from 0 upto n - 1 do
  156.         Print("    " + FormatName(Here()@contents[i]@name) + "\n");
  157.     od;
  158.     fi;
  159.     ForEachAgent(Here(), showAgent);
  160. corp;
  161.  
  162. public proc move(thing where)bool:
  163.  
  164.     if where = nil then
  165.     Print("You can't go that direction.\n");
  166.     false
  167.     else
  168.     OPrint(Me()@p_pName + " leaves.\n");
  169.     SetLocation(where);
  170.     OPrint(Me()@p_pName + " arrives.\n");
  171.     lookAround();
  172.     true
  173.     fi
  174. corp;
  175.  
  176. /* Next, the commands for moving. */
  177.  
  178. public proc goNorth()bool:
  179.     move(Here()@north)
  180. corp;
  181.  
  182. public proc goSouth()bool:
  183.     move(Here()@south)
  184. corp;
  185.  
  186. public proc goEast()bool:
  187.     move(Here()@east)
  188. corp;
  189.  
  190. public proc goWest()bool:
  191.     move(Here()@west)
  192. corp;
  193.  
  194. Verb0(G, "north", 0, goNorth).
  195. Synonym(G, "north", "n").
  196. Verb0(G, "south", 0, goSouth).
  197. Synonym(G, "south", "s").
  198. Verb0(G, "east", 0, goEast).
  199. Synonym(G, "east", "e").
  200. Verb0(G, "west", 0, goWest).
  201. Synonym(G, "west", "w").
  202.  
  203. /* Now, commands for getting and dropping things. */
  204.  
  205. public proc get(string what)bool:
  206.     thing object;
  207.     status st;
  208.  
  209.     if what = "" then
  210.     Print("You must say what you want to get.\n");
  211.     false
  212.     else
  213.     st := FindName(Here()@contents, name, what);
  214.     if st = fail then
  215.         Print("There is no " + FormatName(what) + " here.\n");
  216.         false
  217.     elif st = continue then
  218.         Print(FormatName(what) + " is ambiguous.\n");
  219.         false
  220.     else
  221.         object := FindResult();
  222.         AddTail(Me()@carrying, object);
  223.         DelElement(Here()@contents, object);
  224.         Print(FormatName(what) + " taken.\n");
  225.         true
  226.     fi
  227.     fi
  228. corp;
  229.  
  230. public proc drop(string what)bool:
  231.     thing object;
  232.     status st;
  233.  
  234.     if what = "" then
  235.     Print("You must say what you want to drop.\n");
  236.     false
  237.     else
  238.     st := FindName(Me()@carrying, name, what);
  239.     if st = fail then
  240.         Print(AAn("You are not carrying", FormatName(what)) + ".\n");
  241.         false
  242.     elif st = continue then
  243.         Print(FormatName(what) + " is ambiguous.\n");
  244.         false
  245.     else
  246.         object := FindResult();
  247.         AddTail(Here()@contents, object);
  248.         DelElement(Me()@carrying, object);
  249.         Print(FormatName(what) + " dropped.\n");
  250.         true
  251.     fi
  252.     fi
  253. corp;
  254.  
  255. Verb1(G, "get", 0, get).
  256. Synonym(G, "get", "take").
  257. Verb1(G, "drop", 0, drop).
  258.  
  259. /* A couple of 'utility' commands. */
  260.  
  261. public proc bye()bool:
  262.  
  263.     Print("Bye-bye! Come again soon!\n");
  264.     Quit();
  265.     true
  266. corp;
  267.  
  268. Verb0(G, "bye", 0, bye).
  269. Synonym(G, "bye", "quit").
  270.  
  271. public proc inventory()bool:
  272.     int n, i;
  273.  
  274.     n := Count(Me()@carrying);
  275.     if n = 0 then
  276.     Print("You are not carrying anything.\n");
  277.     else
  278.     Print("You are carrying:\n");
  279.     for i from 0 upto n - 1 do
  280.         Print("    " + FormatName(Me()@carrying[i]@name) + "\n");
  281.     od;
  282.     fi;
  283.     true
  284. corp;
  285.  
  286. Verb0(G, "inventory", 0, inventory).
  287. Synonym(G, "inventory", "i").
  288.  
  289. public proc look()bool:
  290.     lookAround();
  291.     true
  292. corp;
  293.  
  294. Verb0(G, "look", 0, look).
  295. Synonym(G, "look", "l").
  296.  
  297. /* And now, the command which lets you win this little game. */
  298.  
  299. public proc open(string openWhat, withWhat)bool:
  300.     thing object;
  301.     status st;
  302.     string name2;
  303.  
  304.     name2 := FormatName(withWhat);
  305.     if openWhat == "chest" or openWhat == "chest;large" then
  306.     if Here() = insideHut then
  307.         st := FindName(Me()@carrying, name, withWhat);
  308.         if st = fail then
  309.         Print(AAn("You are not carrying", name2) + ".\n");
  310.         false
  311.         elif st = continue then
  312.         Print(name2 + " is ambiguous.\n");
  313.         false
  314.         else
  315.         object := FindResult();
  316.         if object ~= ironKey then
  317.             Print("You can't open things with that!\n");
  318.             false
  319.         else
  320.             Print("You open the chest with the iron key.\n");
  321.             Print("Congratulations! You have solved the puzzle.\n");
  322.             true
  323.         fi
  324.         fi
  325.     else
  326.         Print("There is no chest here.\n");
  327.         false
  328.     fi
  329.     else
  330.     Print("You can't open that!\n");
  331.     false
  332.     fi
  333. corp;
  334.  
  335. Verb2(G, "open", Word(G, "with"), open).
  336. Synonym(G, "open", "unlock").
  337.  
  338.  
  339. /* The routine needed to get and parse the player's input. */
  340.  
  341. public proc parseInput(string inputLine)void:
  342.  
  343.     if SubString(inputLine, 0, 1) = "\"" then
  344.     Say(SubString(inputLine, 1, Length(inputLine) - 1));
  345.     else
  346.     ignore Parse(G, inputLine);
  347.     fi;
  348. corp;
  349.  
  350.  
  351. /* And, finally, the startup stuff, where a new player connects. */
  352.  
  353. public proc newPlayer()void:
  354.  
  355.     Me()@carrying := CreateThingList();
  356.     SetLocation(clearing);
  357.     ignore SetCharacterInputAction(parseInput);
  358.     Print("Welcome to the simple MUD world, " + Me()@p_pName +
  359.     "! We hope you have fun with MUD.\n\n");
  360.     lookAround();
  361. corp;
  362.  
  363. ignore SetNewCharacterAction(newPlayer).
  364.